/////////////////////////////////////////////////////////////////////////
// $Id: stats.h 10613 2011-08-21 16:44:02Z xint $
/////////////////////////////////////////////////////////////////////////
//
//   Copyright (c) 2007-2011 Stanislav Shwartsman
//          Written by Stanislav Shwartsman [sshwarts at sourceforge net]
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
//
/////////////////////////////////////////////////////////////////////////

#ifndef BX_STATS_H
#define BX_STATS_H

#include "bochs.h"

#define BX_STATS_THIS_PTR  this->

#define BX_BLOCKLIST_SIZE 4096

/// bxCPUControl_c - implements processor control object.
class bxCPUControl_c 
{
public:
  Bit32u flushcc;   // flush the code cache.
  Bit32u nocache;   // do not cache entries.
};
/// bxCPUStats_c - implements cpu statistics object. 
class bxCPUStats_c : public logfunctions 
{
public:
  // ========================================
  //  interpreter statistics.               
  // ========================================
  Bit64u interp_icount;  // instructions executed by the interpreter.
  Bit64u interp_bicount; // on-bb instructions executed by the interpreter.
  Bit64u interp_ticount; // on-trace instructions executed by the interpreter.
  Bit64u interp_bcount;  // basicblock executed by the interpreter.
  Bit64u interp_tcount;  // trace entered by the interpreter.
  Bit64u interp_tbcount; // basic block executed in trace by the interpreter.
  Bit64u interp_aexit;   // Asynchronous Exits.

  // ========================================
  //  compiled code statistics.           
  // ========================================
  Bit64u comp_icount;    // instructions executed by traces.
  Bit64u comp_count;     // traces entered by the compiled code.
  Bit64u comp_mcount;    // traces not yet available.
  Bit64u comp_hcount;    // trace heads allocated.
  Bit64u sexit_count;    // side exit count.
  Bit64u aexit_count;    // asynchrounous trace exit count.
  Bit64u fexit_count;    // trace complete count.
  Bit64u bxcall_count;   // number of bxcall from the traces.

  // ========================================
  //  cpu block execution statistics.   
  // ========================================
  Bit64u block_count;                       // total number of blocks.
  Bit64u last_block;                        // last executed block.
  Bit64u block_list[BX_BLOCKLIST_SIZE];     // a list of executed blocks.

  // ========================================
  //  other statistics.                
  // ========================================
  Bit64u entry_count;    // Number of entries built.
  Bit64u entry_lookup;   // number of times entry lookup performed.
  Bit64u ontrace_test;   // number of on trace tests performed.
  Bit64u wtrace_count;   // number of times watched trace is executed.
  Bit64u priv_bcount;    // private basic block count.
  Bit64u priv_tcount;    // private trace count.
  Bit64u tlb_dcount;     // TLB drop event count.
  Bit64u icache_fcount;  // ICache flush event count.
  Bit64u picache_fcount; // Private icache flush event count.
  Bit64u find_entry; 
  Bit64u find_priv_entry;
  Bit64u find_shared_entry;
  Bit64u assist_events; //
  Bit64u smc_events;
  Bit64u tlb_events;
  Bit64u reset_events; 
  Bit64u icache_flush_events;
  Bit64u priv_entry;
  Bit64u shared_entry;
  Bit64u icache_miss;
  Bit64u hlt_count;
  Bit64u page_check_count;

public:
  /// @ constructor
  bxCPUStats_c(void) : interp_icount(0), interp_bicount(0),
                       interp_ticount(0), interp_bcount(0), 
                       interp_tcount(0), interp_tbcount(0), 
                       comp_icount(0), comp_count(0), 
                       comp_mcount(0), comp_hcount(0), 
                       fexit_count(0),  interp_aexit(0),
                       sexit_count(0), aexit_count(0), 
                       bxcall_count(0), entry_lookup(0), ontrace_test(0),
                       wtrace_count(0), block_count(0), priv_bcount(0),
                       priv_tcount(0), tlb_dcount(0), find_entry(0), find_priv_entry(0), find_shared_entry(0),
                       hlt_count(0), page_check_count(0) 
  {
    // do nothing.
  }
};

/// @ bxCOMPStats_c - implements a compiler statistics object. 
class bxCOMPStats_c : public logfunctions 
{
public:

   // ========================================
   //  compilation count statistics.                           
   // ========================================
   Bit64u comp_bcount;              // number of basic blocks compiled.
   Bit64u comp_tcount;              // number of traces compiled.

   // ========================================
   //  compilation rejection statistics.                          
   // ========================================
   Bit64u comp_reject_jit;          // refuses to compile any unit.
   Bit64u comp_reject_bb;           // refuses to compile basicblocks.
   Bit64u comp_reject_trace;        // refuses to compile traces.
   Bit64u comp_reject_phys;         // refuses to be compiled due to physaddr.
   Bit64u comp_reject_rep;          // refuses to be compiled due to repeat.
   Bit64u comp_reject_page;         // refuses to be compiled due to page boundary.

   // ========================================
   //  compilation invalidation statistics.  
   // ========================================
   Bit64u comp_binval_count;        // number of basic blocks invalidated.
   Bit64u comp_tinval_count;        // number of traces invalidated.

   // ========================================
   //  other statistics.                
   // ========================================
   Bit64u comp_totaltime;           // total compilation time.
   Bit64u comp_totalblen;           // the number of instructions contained in basicblocks.
   Bit64u comp_totaltlen;           // the number of basic blocks contained in traces.
   Bit64u comp_linkstub;             
   Bit64u comp_linked;              // the number of blocks linked.
   Bit64u comp_unlinked;            // the number of blocks unlinked.
   Bit64u comp_wait_count;

public:
   /// @ constructor
   bxCOMPStats_c(void) : comp_bcount(0), comp_tcount(0), comp_reject_jit(0), comp_reject_bb(0), comp_reject_trace(0), 
                         comp_reject_phys(0), comp_reject_rep(0),
                         comp_reject_page(0), comp_binval_count(0),
                         comp_tinval_count(0), comp_totaltime(0),
                         comp_totaltlen(0), comp_totalblen(0), comp_linked(0), comp_unlinked(0)
   {
     // do nothing.
   }
};

#endif // BX_STATS_H 

